package com.utils;

import javax.servlet.http.HttpServletRequest;

/**
 * IpUtil.java
 *
 * @author Liang 649355204@qq.com
 * CreateTime 2019/8/13 16:02
 */
public class IpUtil {
    public static final String UNKNOWN = "unknown";

    public static String getIp(HttpServletRequest request){
        String ip = request.getHeader("x-forwarded-for");
        if(ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)){
            ip = request.getHeader("Proxy-Client-IP");
        }
        if(ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)){
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if(ip == null || ip.length() == 0 || UNKNOWN.equalsIgnoreCase(ip)){
            ip = request.getRemoteAddr();
        }
        return ip;
    }
}
